<style>
    .border_bottom{
        border-bottom:1px solid #E7E7E7;
    
    }
    .site-wrapper {
    margin: 0 auto;
    }
    .bm-view {
    width: 100%;
    height: 300px;
    margin-bottom: 20px;
    }
    .cropper-wrapper {
    margin-top: 10px;
    height: 400px;
    }
    .cropper-box{
    height: 300px;
    }
    .btn {
    display: inline-block;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    background: #fff;
    border: 1px solid #c0ccda;
    color: #1f2d3d;
    text-align: center;
    box-sizing: border-box;
    outline: none;
    margin:20px 10px 0px 0px;
    padding: 9px 15px;
    font-size: 14px;
    border-radius: 4px;
    color: #fff;
    background-color: #50bfff;
    border-color: #50bfff;
    transition: all .2s ease;
    text-decoration: none;
    user-select: none;
    }
    .iconclass{
        display: inline-block;
        width: 58px;
        background: #fff;
        border: 1px dashed #757F98;
        border-radius: 4px;
        text-align: center;
        cursor: pointer;
        position: relative;
        overflow: hidden;
        transition: border-color .2s ease;
        height:58px;
        line-height: 58px;
        vertical-align: middle;
        margin-right: 20px;
    }
    .span{
        height: 100px;
        line-height: 100px;
        display: inline-block;
        color: #F29F43;
        font-size: 16px;
        margin-right: 20px;
        padding-left: 10px;
        font-weight: 600;
    }
    
</style>
<style>
    .amap-demo {
        height: 300px !important;
        margin-bottom:15px;
    }
    .teshu .ivu-form-item-label{
        /* margin-top: 1px ;    添加地址点击功能需要加上*/
    }
    .ding.ivu-btn{
        border-radius: none !important;
    }
    .parter_box .ivu-input-group-append{
        border-radius:0px 2px 2px 0 !important;
        background-color:#FAFAFA;
        border-color:#BEBEBE;
    }
    .common-box-body .ivu-form-item label{
        padding-left:10px;
        padding-right:10px;
    }
</style>
<template>
    <div class="parter_box">
        <product-title></product-title>
        <div class="site-wrapper form-box ">
            <Form ref="formItem" :model="formItem"  :rules="ruleValidate" :label-width="110">
                <Row class="common-box-header" >
                    <i-col span="24">
                        <h3>基本信息</h3>
                    </i-col>
                </Row>
                
                <div class="common-box-body" style="padding-top:10px;">
                    <Row>
                        <i-col :md="24" :lg="12">
                            <FormItem label="供应商全称" prop="cid" >
                                <Select v-model="formItem.cid" filterable disabled  placeholder="请选择供应商">
                                    <Option :value="formItem.cid" :key="formItem.cid" >{{formItem.name}}</Option>
                                </Select>
                            </FormItem>
                        </i-col>
                        <i-col :md="24" :lg="12">
                            <Form-item label="总部地址" prop="addr" class="teshu">
                                <Input v-model="formItem.addr" placeholder="请输入总部地址"></Input>
                                <!-- <Button slot="append" @click="addressChange()" class="ding">在地图中定位</Button> -->
                                
                            </Form-item>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col :md="24" :lg="6">
                            <Form-item label="供应商简称" prop="shortn">
                                <Input v-model="formItem.shortn" placeholder="请输入供应商简称"></Input>
                            </Form-item>
                        </i-col>
                        <i-col :mg="24" :lg="6">
                            <Form-item label="供应商代码" prop="parter_code" >
                                <Input v-model="formItem.parter_code" placeholder="请输入供应商代码"></Input>
                            </Form-item>
                        </i-col>
                        <i-col :md="24" :lg="6">
                            <Form-item label="注册资本" prop="regist_capital">
                                <Input v-model="formItem.regist_capital" placeholder="请输入注册资本"></Input>
                            </Form-item>
                        </i-col>
                        <i-col :md="24" :lg="6">
                            <Form-item label="设立时间">
                                <Date-picker type="date" placeholder="选择日期" v-model="formItem.regist_dateTime" @on-change="dateChange($event,formItem,'regist_date')" :options="options3"></Date-picker>
                            </Form-item>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col :md="24" :lg="6">
                            <Form-item label="合作类型" prop="type">
                                <Select v-model="formItem.type" :value="formItem.type" placeholder="请选择合作类型">
                                    <Option value="1">战略合作</Option>
                                    <Option value="2">创新合作</Option>
                                    <Option value="3">联盟合作</Option>
                                </Select>
                            </Form-item>
                        </i-col>
                        <i-col :md="24" :lg="6">
                            <Form-item label="合作状态" prop="status">
                                <Select v-model="formItem.status" :value="formItem.status" placeholder="请选择合作状态">
                                    <Option value="1">合作</Option>
                                    <Option value="2">暂停</Option>
                                    <Option value="3">未启动</Option>
                                </Select>
                            </Form-item>
                        </i-col>
                        <i-col :md="24" :lg="6">
                            <Form-item label="官网网址" prop="website">
                                <Input v-model="formItem.website" placeholder="请输入官网网址" type="url"></Input>
                            </Form-item>
                        </i-col>
                         <i-col :md="24" :lg="6">
                            <Form-item label="公司注册地" prop="regist_addr">
                                <Input v-model="formItem.regist_addr" placeholder="请输入公司注册地"></Input>
                            </Form-item>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col :md="24" :lg="6">
                            <Form-item label="开始时间" prop="contract_start">
                                <Date-picker type="date" placeholder="选择日期" v-model="formItem.contract_start_time" @on-change="dateChange($event,formItem,'contract_start')"></Date-picker>
                            </Form-item>
                        </i-col>
                        <i-col :md="24" :lg="6">
                            <Form-item label="结束时间" prop="contract_end">
                                <Date-picker type="date" placeholder="选择日期" v-model="formItem.contract_end_time" @on-change="dateChange($event,formItem,'contract_end')"></Date-picker>
                            </Form-item>
                        </i-col>
                         <i-col :md="24" :lg="6">
                            <Form-item label="服务热线" prop="tel">
                                <Input v-model="formItem.tel"  placeholder="格式为400-123456-123或123456"></Input>
                            </Form-item>
                        </i-col>
                        <i-col :md="24" :lg="6">
                            <Form-item label="渠道服务电话" prop="service_tel">
                                <Input v-model="formItem.service_tel"  placeholder="格式为400-123456-123或123456"></Input>
                            </Form-item>
                        </i-col>
                    </Row>
                    <!-- <Row>
                        <i-col :md="24" :lg="6">
                            <Form-item label="经纬度" prop="plan">
                                <Input v-model="lat_lng" placeholder="请输入经纬度" disabled></Input>
                            </Form-item>
                        </i-col>
                    </Row>
                    <Row v-show="mapShow">
                        <i-col :md="24" :lg="15">
                            <el-amap vid="amapDemo" class="amap-demo" :plugin="plugins" :center="mapCenter" style="padding:10px;border: 1px solid #EDEDED">
                            </el-amap>
                        </i-col>
                    </Row> -->
                </div>
                <Row class="common-box-header">
                    <i-col span="24">
                        <h3>其他信息</h3>
                    </i-col>
                </Row>
                <Row class="border_bottom mb24">
                    <i-col :md="24" :lg="8">
                            <span class="span">
                                logo上传
                            </span>
                        <span class="iconclass" @click="openModal('logo')">
                                <Icon  type="camera" size="20"></Icon>
                                <img   width="58" height="58"/>
                            </span>
                        <span style="height: 80px;display: inline-block;vertical-align: middle;">
                                <img :src="formItem.logo" alt="" style="width: 58px;height: 58px;margin-top:11px;">
                            </span>
                    </i-col>
                    <i-col :md="24" :lg="8">
                        <span class="span">
                                APP二维码
                        </span>
                        <span class="iconclass" @click="openModal('app_qr_code')">
                            <Icon type="camera" size="20"></Icon>
                            <img   width="58" height="58"/>
                        </span>
                        <span style="height: 80px;display: inline-block;vertical-align: middle;">
                            <img :src="formItem.app_qr_code" alt="" style="width: 58px;height: 58px;margin-top:11px;">
                        </span>
                    </i-col>
                    <i-col :md="24" :lg="8">
                        <span class="span">
                                公众号二维码
                        </span>
                        <span class="iconclass" @click="openModal('wechat_qr_code')">
                            <Icon  type="camera" size="20"></Icon>
                                    <!-- <img v-show="!nowechat" :src="formItem.wechat_qr_code" width="58" height="58"/> -->
                        </span>
                        <span style="height: 80px;display: inline-block;vertical-align: middle;">
                            <img :src="formItem.wechat_qr_code" alt="" style="width: 58px;height: 58px;margin-top:11px;">
                        </span>
                    </i-col>
                </Row>
                <div class="common-box-body">
                    <Row class="border_bottom mb24">
                        <i-col :md="24" :lg="12">
                            <Form-item label="APP名称" prop="app_name">
                                <Input v-model="formItem.app_name" placeholder="请输入APP名称"></Input>
                            </Form-item>
                        </i-col>
                        <i-col :md="24" :lg="12">
                            <Form-item label="微信公众号" prop="wechat_name">
                                <Input v-model="formItem.wechat_name" placeholder="请输入微信公众号名称"></Input>
                            </Form-item>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col :md="24" :lg="24">
                            <Tabs type="card">
                                <TabPane label="公司简介">
                                    <UE :defaultMsg="formItem.description" ref="description" id="description"></UE>
                                </TabPane>
                                <TabPane label="公司荣誉">
                                    <UE :defaultMsg="formItem.honor"  ref="honor" id="honor"></UE>
                                </TabPane>
                                <TabPane label="发展历程">
                                    <UE :defaultMsg="formItem.history" ref="history" id="history"></UE>
                                </TabPane>
                            </Tabs>
                        </i-col>
                    </Row>
                </div>
            </Form>
           <div id="footer" class="pt22">
                <Button v-if="$isShow('parter/update')" type="primary" shape="circle" id="submit" @click="handleSubmit('formItem')" style="border-radius: 30px !important;">
                    <Icon type="checkmark-circled"></Icon>
                    保存 / 提交
                </Button>
                <Button id="back" shape="circle" @click="back" style="border-radius: 30px !important;">返回</Button>
            </div>
        </div>
         
        <Modal v-model="modal2" width="1200" ok-text="上传图片" :loading="loading" @on-ok="uploadHeadimg" @on-cancel="cancel">
            <Row class="cropper-wrapper">
                <Col span="11" class="cropper-box">
                <vueCropper
                    ref="cropper"
                    :img="headImg.img"
                    :outputSize="headImg.size"
                    :outputType="headImg.outputType"
                    :info="headImg.info"
                    :canScale="headImg.canScale"
                    :autoCrop="headImg.autoCrop"
                    :autoCropWidth="headImg.width"
                    :autoCropHeight="headImg.height"
                    :fixed="headImg.fixed"
                    :fixedNumber="headImg.fixedNumber"
                    @realTime="realTime"
                ></vueCropper>
                <label class="btn" for="upload2">打开图片</label>
                <input type="file" id="upload2" style="position:absolute; clip:rect(0 0 0 0);" accept="image/png, image/jpeg, image/gif, image/jpg" @change="uploadImg($event)">
                <!-- <button @click="finish2('base64')" class="btn">裁剪</button> -->
                </Col>
                <Col span="7" offset="1">
                <!-- <img :src="formItem.headImg.demoimg" /> -->
                <div class="show-preview" :style="{'width': previews.w + 'px', 'height': previews.h + 'px',  'overflow': 'hidden', 'margin': '5px'}">
                    <div :style="previews.div">
                        <img :src="headImg.img" :style="previews.img">
                    </div>
                </div>
                </Col>
            </Row>
        </Modal>
    </div>
</template>
<script>
    import productTitle from '../../components/productTitle';
    import city from '../../asset/js/city';
    import VueCropper from 'vue-cropper';
    import { lazyAMapApiLoaderInstance  } from 'vue-amap';
    import { getCompany2   ,updateCom , saveCom , getDatil} from '../../api/parter';




    //新
    import {_all_company,_parter_info,_parter_update,} from '../../api/parter'
    import UE from '../UE/ue.vue';
    //
    import '../../../static/UEdit/ueditor.config.js';
    import '../../../static/UEdit/ueditor.all.js';
    import '../../../static/UEdit/lang/zh-cn/zh-cn.js';
    import '../../../static/UEdit/ueditor.parse.js';
    import { getStsTokenWrite,getStsTokenRead } from '../../api/common';
    export default {
        data () {
             const validateMobile =(rule, value, callback)=>{
                    var re=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)|(^[0-9]{3,4}\-[0-9]{3,8}\-[0-9]{0,5})/;
                    if(!re.test(value)){
                        callback(new Error('请输入正确电话'));
                    }
                };
            return {
                //控制设立时间不能在当前时间之后
                options3:{
                    disabledDate (date) {
                        return date && date.valueOf() > Date.now() ;
                    }
                },
                mapShow:false,
                files:{},
                defaultMsg: '',
                config: {
                    initialFrameWidth: null,
                    initialFrameHeight: 350
                },
                id:'',
                spinShow:true,
                address:'',
                plugins: ['Geolocation','PlaceSearch'],
                mapCenter:[113.63305, 34.767174],
                map:{},
                area_data: city,
                initiallist:[
                    'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
                ],
                canchange:false,
                formItem:{
                    id:0,
                    parter_code:'',
                    cid:'',
                    name:'',
                    shortn:'',
                    logo:'',
                    app_name:'',
                    app_qr_code:'',
                    wechat_name:'',
                    wechat_qr_code:'',
                    lat:'',
                    lng:'',
                    status:'3',
                    regist_date:'',
                    regist_dateTime:'',
                    type:'1',
                    addr:'',
                    province:1,
                    city:1,
                    county:1,
                    province_name:"",
                    city_name:"",
                    county_name:"",
                    website:'',
                    tel:'',
                    cooperation_type:'',
                    regist_addr:'',
                    description:'',
                    honor:'',
                    history:'',
                    contract_start_time:'',
                    contract_start:'',
                    contract_end_time:'',
                    contract_end:'',
                },
                ruleValidate:{
                    cid:[
                        { required: true,  message: '供应商不能为空', }
                    ],
                    name:[
//                    { required: true, message: '供应商全程不能为空', trigger: 'blur,change' }
                    ],
                    shortn:[
                        { required: true, message: '供应商简称不能为空', trigger: 'blur,change' }
                    ],
                    contract_start:[
                   { required: true, message: '合约开始时间不能为空',trigger: 'blur,change'}
               ],
               contract_end:[
                   { required: true, message: '合约结束时间不能为空'}
               ],
               
               website:[
                   { message:'网址以http://或者https://开头',trigger: 'change',type:'url'}
               ],
                service_tel:[
                    {message:'请输入正确电话',trigger: 'blur'}
               ],
               tel:[
                    {message:'请输入正确电话',trigger: 'blur,change'}
               ],
//                cooperation_type:[
//                    { required: true, message: '合作类型不能为空', trigger: 'blur,change' }
//                ],
                    status:[
                        { required: true, message: '合作状态不能为空'}
                    ],
                    type:[
                        { required: true, message: '合作类型不能为空' }
                    ],
                },
                allComList:{},
                nohead:true,
                noapp:true,
                nowechat:true,
                loading: true,
                headImg: {
                    img: '',
                    info: true,
                    size: 1,
                    canScale:true,
                    outputType: 'jpeg',
                    autoCrop: true,
                    // 只有自动截图开启 宽度高度才生效
                    autoCropWidth: 200,
                    autoCropHeight: 200,
                    // 开启宽度和高度比例
                    fixed: true,
                    fixedNumber: [1, 1],
                    demoimg:'',
                },
                modal2: false,
                previews: {},
                imgname:'',
                _Marker:{},
                statustext:[
                    {
                        value:1,
                        text:'正常'
                    },
                    {
                        value:2,
                        text:'暂停'
                    },
                    {
                        value:3,
                        text:'未启动'
                    },
                ],
            }
        },
        components: {
            productTitle,
            VueCropper,
            UE
        },
        computed:{
            lat_lng:function(){
                if(!this.formItem.lat||!this.formItem.lng){
                    return '';
                }else{
                    console.log(this.formItem.lat+','+this.formItem.lng,"222")
                    return this.formItem.lat+','+this.formItem.lng;
                }
            }
        },
        created(){
            // this.getAllcompany();
            this.get_detail();
        },
        activated(){
        },
        watch:{
        },
        mounted() {
            
            lazyAMapApiLoaderInstance.load().then(() => {
                this.map = new AMap.Map('amapDemo', {
                    center:this.mapCenter,
                    zoom:15
                });
                this._Marker = new AMap.Marker({
                    map:null,
                })
                var _self = this
                this.map.on("click",function(event){
                    _self.formItem.lng = event.lnglat.lng;
                    _self.formItem.lat = event.lnglat.lat;
                    setTimeout(function(){
                        _self.mapShow = false;
                    },1000)
                })
                AMap.event.addListener(this._Marker,'dragend',function(){
//                alert(this._Marker.getPosition( ))
//                alert(getPosition( ))
                })
//
            });
        },
        methods: {
            cancel(){
                document.getElementById("upload2").value  = ''
                this.$refs.cropper.refresh()
            },
            getUEContent() {
                this.formItem.description = this.$refs.description.getUEContent();
                this.formItem.honor = this.$refs.honor.getUEContent();
                this.formItem.history = this.$refs.history.getUEContent();
            },
            companyChange(){
                let params={
                    parter_id:103
                }
                new Promise((rev,rej)=>{
                    _parter_info(params).then(res=>{
                        if(res.data.err==0){
                            this.formItem.parter_code = res.data.data.parter_code;
                            this.formItem.name = res.data.data.name;
                            this.formItem.shortn = res.data.data.shortn;
                            this.formItem.website = res.data.data.website;
                            this.formItem.type = res.data.data.type?res.data.data.type:this.formItem.type;
                            this.formItem.tel = res.data.data.tel;
                            this.formItem.status = res.data.data.status?res.data.data.status:this.formItem.status;
                            this.formItem.logo = res.data.data.logo;
                            this.formItem.regist_capital = res.data.data.regist_capital;
                            this.formItem.regist_date = res.data.data.regist_date;
                            this.formItem.regist_dateTime = res.data.data.regist_date;
                            this.formItem.app_name = res.data.data.app_name;
                            this.formItem.app_qr_code = res.data.data.app_qr_code;
                            this.formItem.wechat_name = res.data.data.wechat_name;
                            this.formItem.wechat_qr_code = res.data.data.wechat_qr_code;
                            this.formItem.addr = res.data.data.addr;
                            this.formItem.regist_addr = res.data.data.regist_addr;


                            this.formItem.description = res.data.data.description;
                            this.$refs.description.setUEContent(res.data.data.description);


                            this.formItem.honor = res.data.data.honor;
                            this.$refs.honor.setUEContent(res.data.data.honor);


                            this.formItem.history = res.data.data.history;
                            this.$refs.history.setUEContent(res.data.data.history);


                            this.formItem.lat = res.data.data.lat;
                            this.formItem.lng = res.data.data.lng;
                        }else{
                            this.$Message.error(res.data.info);
                        }
                        rev();
                    }).catch(error=>{
                        rej(error)
                    })
                })
            },
            companyChange1(value) {
                this.formItem.cid = this.allComList[value].id;
                this.formItem.name =  this.allComList[value].name;
                this.formItem.shortn =  this.allComList[value].short;
                this.formItem.regist_date = this.allComList[value].build_date;
                this.formItem.regist_dateTime = this.allComList[value].build_date;
                //状态需再次确认
                this.formItem.status = this.allComList[value].status?this.allComList[value].status.toString():'1';
                //这里当 lat  lng为0时，显示为 天安门  位置
                if(this.allComList[value].lng!='0'){
                    this.mapCenter[0] = this.allComList[value].lng;
                    this.mapCenter[1] = this.allComList[value].lat;
                    this.formItem.lat = this.allComList[value].lat;
                    this.formItem.lng = this.allComList[value].lng;
                }else{
                    this.mapCenter[1] = '39.903794';
                    this.mapCenter[0] = '116.39784';
                    this.formItem.lat = '39.903794';
                    this.formItem.lng = '116.39784';
                }
                this.$refs.description.setUEContent(this.allComList[value].description)
                this.$refs.history.setUEContent(this.allComList[value].history)
                this.$refs.honor.setUEContent(this.allComList[value].honor)


//                this.formItem.description = this.allComList[value].description;
//                this.formItem.history = this.allComList[value].history;
                this.formItem.regist_capital = this.allComList[value].regist_capital;
                this.formItem.special = this.allComList[value].special;
                this.formItem.tel = this.allComList[value].tel;
                this.formItem.website = this.allComList[value].website;
                this.formItem.addr = this.allComList[value].add;
                this.formItem.regist_addr = this.allComList[value].regist_addr;
//                this.formItem.type = this.allComList[value].type?this.allComList[value].type.toString:'1';
                this.formItem.wechat_name = this.allComList[value].wechat_name;
                this.formItem.wechat_qr_code = this.allComList[value].wechat_img;
                this.formItem.app_name = this.allComList[value].app_name;
                this.formItem.app_qr_code = this.allComList[value].app_qr_code;
                this.formItem.logo = this.allComList[value].logo;
                this.map.setCenter(this.mapCenter);
                this._Marker.setPosition(this.mapCenter);
                this._Marker.setMap(this.map);
                if(this.formItem.logo){
                    this.nohead = false
                }
                if(this.formItem.app_qr_code){
                    this.noapp = false
                }
                if(this.formItem.wechat_qr_code){
                    this.nowechat = false
                }
//            }
            },
            getAllcompany() {
                new Promise((resolve, reject) => {
                    _all_company().then(response => {
                        if(response.data.err == 0){
                            this.allComList = response.data.data;
                        } else {
                            this.$Message.error(response.data.info);
                        }
//                    resolve(this.getDetail());
                    }).catch(error => {
                        reject(error);
                    });
                });
            },
            openModal(name){
                this.modal2 = true
                this.imgname =  name
            },
            uploadImg (e) {
                //上传图片
                var file = e.target.files[0];
                if (!/\.(gif|jpg|jpeg|png|bmp|GIF|JPG|PNG)$/.test(e.target.value)) {
                    alert('图片类型必须是.gif,jpeg,jpg,png,bmp中的一种')
                    return false
                }
                var reader = new FileReader()
                reader.onload = (e) => {
                    this.headImg.img = e.target.result

                }
                reader.readAsDataURL(file);
            },
            // 实时预览函数
            realTime (data) {
                this.previews = data
            },
            toBlob(urlData, fileType) {
                var bytes = window.atob(urlData),
                    n = bytes.length,
                    u8arr = new Uint8Array(n);
                while (n--) {
                    u8arr[n] = bytes.charCodeAt(n);
                }
                return new Blob([u8arr], {
                    type: fileType
                });
            },
            uploadHeadimg () {
                this.$refs.cropper.getCropBlob((data) => {
                    //this.customer.avator = data
                    //this.formItem.logo = data
                    getStsTokenWrite().then((res)=>{
                        if(res.data.err==0){
                            var sts = res.data.data.Credentials;
                            var client = new OSS.Wrapper({
                                region:'oss-cn-hangzhou',
                                accessKeyId: sts.AccessKeyId,
                                accessKeySecret: sts.AccessKeySecret,
                                stsToken: sts.SecurityToken,
                                bucket: 'kuaibao-imgs',
                                secure: true, 
                            });
                            const files = document.getElementById('upload2').files[0];
                            let _this  =this;
                            var reader = new FileReader();
                            reader.readAsArrayBuffer(data);
                            let name = files.name;
                            name= name.slice(0,name.lastIndexOf('.'))+Date.parse(new Date())+name.slice(name.lastIndexOf('.'),name.length);
                            reader.onload = function (event) {
                                var buffer = new OSS.Buffer(event.target.result);
                                client.put(name, buffer).then((results) => {
                                    if (results.url) {
                                        if(_this.imgname == 'logo'){
                                            _this.$set(_this.formItem,"logo",results.url)
                                                _this.formItem.logo = results.url;
                                                _this.nohead = false
                                                _this.$refs.cropper.refresh()
                                        }else if(_this.imgname == 'app_qr_code'){
                                            _this.$set(_this.formItem,"app_qr_code",results.url)
                                            _this.noapp = false;
                                                _this.$refs.cropper.refresh()
                                        }else if(_this.imgname == 'wechat_qr_code'){
                                            _this.$set(_this.formItem,"wechat_qr_code",results.url)
                                            _this.nowechat = false;
                                                _this.$refs.cropper.refresh()
                                        }
                                    } else {
                                        _this.$Message.error('上传出错');
                                    }
                                })
                            }
                            
                            
                        }
                    })
                })
                // this.headImg.img="";
                this.modal2 = false;

            },
            uploadHeadimg1 () {
                this.$refs.cropper.getCropData((data) => {
                    //this.customer.avator = data
                    //this.formItem.logo = data
                    getStsTokenWrite().then((res)=>{
                        if(res.data.err==0){
                            let _this = this;
                            var sts = res.data.data.Credentials;
                            var client = new OSS.Wrapper({
                                region:'oss-cn-hangzhou',
                                accessKeyId: sts.AccessKeyId,
                                accessKeySecret: sts.AccessKeySecret,
                                stsToken: sts.SecurityToken,
                                bucket: 'kuaibao-imgs',
                                secure: true, 
                            });
                            // var files = this.files;
                            var base64 = data.split(',')[1];
                            var fileType = data.split(';')[0].split(':')[1];
                            const files = document.getElementById('upload2').files[0];
                            // base64转blob
                            var blob = this.toBlob(base64, fileType);
                            // blob转arrayBuffer
                            var reader = new FileReader();
                            reader.readAsArrayBuffer(blob);
                            let name = files.name;
                            name= name.slice(0,name.lastIndexOf('.'))+Date.parse(new Date())+name.slice(name.lastIndexOf('.'),name.length);
                            // reader.readAsArrayBuffer(blob);
                            // const files = document.getElementById('upload2').files[0];
                            reader.onload=function(event){
                                 var buffer = new OSS.Buffer(event.target.result);
                                //这里用 multipartUpload  上传会报错，所以更改为 put
                                client.put(name, buffer).then((results) => {
                                    if (results.url) {
                                        if(_this.imgname == 'logo'){
                                            _this.$set(this.formItem,"logo",results.url)
                                             _this.formItem.logo = results.url;
                                            _this.nohead = false;
                                            _this.$refs.cropper.refresh()
                                        }else if(_this.imgname == 'app_qr_code'){
                                            _this.$set(this.formItem,"app_qr_code",results.url)
                                            _this.noapp = false;
                                            _this.$refs.cropper.refresh()
                                        }else if(_this.imgname == 'wechat_qr_code'){
                                            _this.$set(_this.formItem,"wechat_qr_code",results.url)
                                            _this.nowechat = false;
                                            _this.$refs.cropper.refresh()
                                        }
                                    } else {
                                        _this.$Message.error('上传出错');
                                    }
                                })
                            }
                        }
                    })
                })
                this.modal2 = false;
            },
//        areaChange(value, selectedData){
//            var _areatxt = ''
//            for(var i = 0,len = selectedData.length;i<len;i++){
//                _areatxt += selectedData[i].label
//            }
////            this.address = _areatxt
////            this.location =
//            this.formItem.province = value[0]
//            this.formItem.city = value[1]
//            this.formItem.county = value[2]
//            this.formItem.province_name = selectedData[0].label
//            this.formItem.city_name = selectedData[1].label
//            this.formItem.county_name = selectedData[2].label
//        },
            addressChange() {
//            var _address = this.address + this.formItem.addr
                var _address =   this.formItem.addr;
                this.onSearchResult(_address)
                this.mapShow = true;
//            AMap.plugin('AMap.Geocoder',function(){
//                var geocoder = new AMap.Geocoder({
//                    city: "010"//城市，默认：“全国”
//                });
//                var marker = new AMap.Marker({
//                    map:this.map,
//                    bubble:true,
//                })
//                this.map.on('click',function(e){
//                    marker.setPosition(e.lnglat);
//                    geocoder.getAddress(e.lnglat,function(status,result){
//                        if(status=='complete'){
////                            input.value = result.regeocode.formattedAddress
//                            message.innerHTML = ''
//                        }else{
//                            message.innerHTML = '无法获取地址'
//                        }
//                    })
//                })
//            })
            },
            onSearchResult(address) {
                var map = this.map
                var local = new AMap.PlaceSearch({
                    map: map
                });
                local.search(address,function(status,result){
                });
                var _self = this
                local.on("markerClick",function(event){
                    _self.formItem.lng = event.data.location.lng;
                    _self.formItem.lat = event.data.location.lat;
                })
            },
            handleSubmit(name){
                this.getUEContent();
                let end = new Date(this.formItem.contract_end).getTime();
                let start = new Date(this.formItem.contract_start).getTime();
                if(start>end){
                    this.$Message.error('结束时间不能小于开始时间');
                    this.formItem.contract_end="";
                    this.formItem.contract_end_time=" ";
                    return false;
                }else{
                    this.$refs[name].validate((valid) => {
                    if (valid) {
                        new Promise((resolve,reject) =>{
                            _parter_update(this.formItem).then(response=>{
                                if(response.data.err==0){
                                    this.$router.push({name:'com_manage'});
                                }else{
                                    this.$Message.error(response.data.info);
                                }
                                resolve();
                            }).catch(error =>{
                                reject(error);
                            });
                        })
                    } else {
                        this.$Message.error('请完善信息!');
                    }
                })
                }
                
            },
            back(){
                this.$router.push({name:'com_manage'});
            },
            get_detail(){
                let params={
                    parter_id:this.$route.params.id
                }
                new Promise((resolve, reject) => {
                    _parter_info(params).then(res => {
                        if(res.data.err == 0){
                            this.formItem.parter_code = res.data.data.parter_code;
                            this.formItem.mid = res.data.data.id;
                            this.formItem.cid = res.data.data.cid;
                            this.formItem.name = res.data.data.name;
                            this.formItem.shortn = res.data.data.shortn;
                            this.formItem.website = res.data.data.website;
                            this.formItem.type = res.data.data.type?res.data.data.type.toString():this.formItem.type;
                            this.formItem.tel = res.data.data.tel;
                            this.formItem.status = res.data.data.status?res.data.data.status.toString():this.formItem.status;
                            this.formItem.logo = res.data.data.logo;
                            this.formItem.regist_capital = res.data.data.regist_capital;
                            this.formItem.regist_date = res.data.data.regist_date;
                            this.formItem.regist_dateTime = res.data.data.regist_date;
                            this.formItem.app_name = res.data.data.app_name;
                            this.formItem.app_qr_code = res.data.data.app_qr_code;
                            this.formItem.wechat_name = res.data.data.wechat_name;
                            this.formItem.wechat_qr_code = res.data.data.wechat_qr_code;
                            this.formItem.addr = res.data.data.addr;
                            this.formItem.regist_addr = res.data.data.regist_addr;

                            this.formItem.description = res.data.data.description;
                            this.$refs.description.setUEContent(res.data.data.description);


                            this.formItem.honor = res.data.data.honor;
                            this.$refs.honor.setUEContent(res.data.data.honor);


                            this.formItem.history = res.data.data.history;
                            this.$refs.history.setUEContent(res.data.data.history);

                            this.formItem.lat = res.data.data.lat;
                            this.formItem.lng = res.data.data.lng;
                            this.formItem.service_tel = res.data.data.service_tel;
                            this.formItem.contract_start = res.data.data.contract_start;
                            this.formItem.contract_start_time = res.data.data.contract_start;
                            this.formItem.contract_end = res.data.data.contract_end;
                            this.formItem.contract_end_time = res.data.data.contract_end;

                            this.mapCenter[0] = res.data.data.lng;
                            this.mapCenter[1] =  res.data.data.lat;
                            this.map.setCenter(this.mapCenter);
                            this._Marker.setPosition(this.mapCenter);
                            this._Marker.setMap(this.map);
                        } else {
                            this.$Message.error(res.data.info);
                        }
                    }).catch(error => {
                        reject(error);
                    });
                });
            },
            dateChange(val,obj,attr){
                    obj[attr] = val;
                    console.log(obj[attr]);
            }
        },
        
    }
</script>